class Registry{
    constructor(){
        this.url="http://localhost/my-wangyi/backend/" //后端公共地址
    };
    init(){
        this.yanzheng();
    }
    yanzheng1(){
        var flag=0;
        var _this=this;
        //手机号验证
        let tel_xinxi=document.querySelector("#tel_xinxi")
        let iphone=document.querySelector("#iphone_1")
        iphone.onblur=function(){
            
            if(this.value!==""){
                let tel_reg=/^1[0-9]{10}$/;
                let tel=this.value;
                
                if(tel.search(tel_reg)!=-1){
                    // tel_xinxi.innerHTML="√"
                    // tel_xinxi.setAttribute("style",'color:green');
                    flag=1;

                    $.ajax({
                        method:'post',
                        url:'http://localhost/my-wangyi/backend/denglu.php',
                        data:{
                            user:$(iphone).val(),
                        },
                        success(result){
                            let result1=JSON.parse(result);
                            if(result1.status==1){
                                tel_xinxi.innerHTML=result1.meg;
                                // tel_xinxi.setAttribute("style",'color:red');
                            }
                            else{
                                tel_xinxi.innerHTML=result1.meg;
                                // tel_xinxi.setAttribute("style",'color:green');

                            }
                           
                        }
                    })
                    

                }else{
                    tel_xinxi.innerHTML="手机号格式错误"
                    tel_xinxi.setAttribute("style",'color:red');
                }
                

            }else{
                tel_xinxi.setAttribute("style",'color:red');
                tel_xinxi.innerHTML="手机号码不能为空"
            }
        }

        //验证码
        //样式
        let yzm=document.querySelector(".hqyzm");
        let yzmxinxi=document.querySelector("#yzm_xinxi");
        yzm.addEventListener("mouseover",function(){//鼠标进入
            yzm.setAttribute("style","background-color: #b8a681;cursor: pointer;");
        })

        yzm.addEventListener("mouseout",function(){//鼠标退出
            yzm.setAttribute("style","background-color:#eeeeee");
        })

        //验证码判断
        
        let submit=document.querySelector("#zhuce_sunmit");
        yzm.addEventListener("click",function(){//验证码生成
            // let iphone_1=document.querySelector("#iphone_2");
            // let iphone_2=document.querySelector("#iphone_2");
            // if( iphone_2.value!=rand){
            //     yzmxinxi.innerHTML="验证码错误"
                
            // }
           rand1();
        })
        function rand1(){
            let rand= parseInt(Math.random()*((999999-100001)+100000));
            yzmxinxi.innerHTML=rand;
        }

            let iphone_2=document.querySelector("#iphone_2");
            let yzmxinxi2=document.querySelector("#yzm_xinxi2");
            iphone_2.onblur=function(){
            if( iphone_2.value!=yzmxinxi.innerHTML||iphone_2.value == ""){
                yzmxinxi2.innerHTML="验证码错误"
                yzmxinxi2.setAttribute("style",'color:red');
                
            }
            else{
                yzmxinxi2.setAttribute("style",'color:green');
                yzmxinxi2.innerHTML="√"
            }
            }
            //单选框 协议判断
            document.querySelector("#checkbox1").onclick=function (){
                if(document.querySelector("#checkbox1").checked==false){
                    document.querySelector("#xieyi_xinxi").innerHTML="请勾选协议"
                }
                else{
                    document.querySelector("#xieyi_xinxi").innerHTML=""
                }
            }

        submit.addEventListener("mouseover",function(){//鼠标进入
            submit.setAttribute("style","cursor: pointer;");
        })
        //判断表单提交
        submit.onclick=function (e){
            submit.style.opacity="0.3"
            setTimeout(()=>{
                this.style.opacity="1";
            },500)
            // e.preventDefault();
            
        if(iphone_2.value==yzmxinxi.innerHTML&&flag==1&&document.querySelector("#checkbox1").checked==true){
     
            $.ajax({
                method:'post',
                url:'http://localhost/my-wangyi/backend/denglu2.php',
                data:{
                    user:$(iphone).val(),
                },
                success(){
                    document.cookie=`xingming=${$(iphone).val()};path=/`
                }
            })
            

        }else{
            e.preventDefault();
            if(document.querySelector("#checkbox1").checked==false){
                document.querySelector("#xieyi_xinxi").innerHTML="请勾选协议"
            }
            else{
                document.querySelector("#xieyi_xinxi").innerHTML=""
            }
            

           if(  iphone.value==""){
                tel_xinxi.setAttribute("style",'color:red');
                tel_xinxi.innerHTML="手机号码不能为空"
                // rand1();
            }

            if( iphone_2.value!=yzmxinxi.innerHTML||iphone_2.value == ""){
                yzmxinxi2.innerHTML="验证码错误"
                yzmxinxi2.setAttribute("style",'color:red');
                rand1();
                
            }
            else{
                yzmxinxi2.setAttribute("style",'color:green');
                yzmxinxi2.innerHTML="√"
            }
            
            

        }   
    }


    }





    yanzheng(){
        var flag=0;
        //手机号验证
        $("#iphone_1").on("blur",function(){
            
            if($(this).val()!==""){
                let tel_reg=/^1[0-9]{10}$/;
                let tel=$(this).val();
                
                if(tel.search(tel_reg)!=-1){
                    
                    flag=1;
                    $.ajax({
                        method:'post',
                        url:'http://localhost/my-wangyi/backend/denglu.php',
                        data:{
                            user: $("#iphone_1").val(),
                        },
                        success(result){
                            let result1=JSON.parse(result);
                            $("#tel_xinxi").html(result1.meg);
                            if(result1.status==0){
                                $("#tel_xinxi").css("color","red")
                            }
                            else{
                                $("#tel_xinxi").css("color","green")
                            }
                        }
                    })
                    
    
                }else{
                    $("#tel_xinxi").html("手机号格式错误")
                    $("#tel_xinxi").attr("style",'color:red');
                }
                
    
            }else{
                $("#tel_xinxi").attr("style",'color:red');
                $("#tel_xinxi").html("手机号码不能为空");
            }
        })
    
        //验证码
        //样式
        $(".hqyzm").on("mouseover",function(){//鼠标进入
            $(this).attr("style","background-color: #b8a681;cursor: pointer;");
        })
        $(".hqyzm").on("mouseout",function(){//鼠标退出
            $(this).attr("style","background-color:#eeeeee");
        })
        //验证码判断
        $(".hqyzm").on("click",function(){
           rand1();
        })
        function rand1(){
            let rand= parseInt(Math.random()*((999999-100001)+100000));
            $("#yzm_xinxi").html(rand);
        }
            $("#iphone_2").on("blur",function(){
                if( $("#iphone_2").val()!=$("#yzm_xinxi").html()||$("#iphone_2").val() == ""){
                    $("#yzm_xinxi2").html("验证码错误");
                    $("#yzm_xinxi2").attr("style",'color:red');
                    
                }
                else{
                    $("#yzm_xinxi2").attr("style",'color:green');
                    $("#yzm_xinxi2").html("√")
                }
                })
            //单选框 协议判断
            $("#checkbox1").on("click",function (){
                if(!$("#checkbox1")[0].checked){
                    $("#xieyi_xinxi").html("请勾选协议")
                }
                else{
                    $("#xieyi_xinxi").html("")
                }
            })
    
        $("#zhuce_sunmit").on("mouseover",function(){//鼠标进入
            $("#zhuce_sunmit").attr("style","cursor: pointer;");
        })
        //判断表单提交
        $("#zhuce_sunmit").on("click",function (e){

            // e.preventDefault();
            
        if($("#iphone_2").val()==$("#yzm_xinxi").html()&&flag==1&&$("#checkbox1")[0].checked==true){
            // $("#zhuce_sunmit").attr("type","submit");
            $.ajax({
                method:'post',
                url:'http://localhost/my-wangyi/backend/denglu2.php',
                data:{
                    user:$("#iphone_1").val(),
                },
                success(){
                    document.cookie=`xingming=${$("#iphone_1").val()};path=/`
                    console.log(1);
                }
            })
            
    
        }else{
            e.preventDefault();
            $("#zhuce_sunmit").css("opacity","0.3");
            setTimeout(()=>{
                $(this).css("opacity","1");
            },500)

            // $("#zhuce_sunmit").attr("type","button");
            if(!$("#checkbox1")[0].checked){
               $("#xieyi_xinxi").html("请勾选协议")
            }
            else{
               $("#xieyi_xinxi").html("")
            }
            
    
           if(  $("#iphone_1").val()==""){
            $("#tel_xinxi").attr("style",'color:red');
            $("#tel_xinxi").html("手机号码不能为空")
                // rand1();
            }
    
            if( $("#iphone_2").val()!=$("#yzm_xinxi").html()||$("#iphone_2").val() == ""){
                $("#yzm_xinxi2").html("验证码错误")
                $("#yzm_xinxi2").attr("style",'color:red');
                rand1();
                
            }
            else{
                $("#yzm_xinxi2").attr("style",'color:green');
                $("#yzm_xinxi2").html("√");
            }
            
            
    
        }   
    })
    
    
    }

}
export{
    Registry
}